/**
 * 红包记录页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：红包记录页面
     创建日期：2015-10-12
     修改记录：
     备注说明：
 */

$(document).ready(function() {
	showRedPackList();
	 $(".date").datepicker({
	        todayBtn: "linked",
	        keyboardNavigation: false,
	        forceParse: false,
	        calendarWeeks: true,
	        autoclose: true
	    });
});

/**
 * 查询红包记录
 * @returns
 */
var showRedPackList = function(){

	var userNickName=$("#userNickName").val();
	var redPackTypes=$("#redPackType").val();
	var userTypes=$("#userTypes").val();
	var sendExpressTime=$("#sendExpressTime").val();
	
	var datas =  {"p":"redPackManage","m":"list","userNickName":userNickName,"redPackTypes":redPackTypes,"userTypes":userTypes,"sendExpressTime":sendExpressTime };
	var columnDefine = {"id":"主键","nickName":"昵称","userType":"用户类型","sendTime":"发放红包时间","amount":"发放金额","status":"发放奖励状态","typeId":"红包类别"};
	
	var formatters={
	            "sendTime": function (column, rowData)
	            {
    				return timeFormatTrans(rowData.sendTime);
	            },
	            "userType": function (column, rowData)
	            {
	            	return rowData.userType == 0 ? '发件人':'快递员';
	            },
	            "typeId": function (column, rowData)
	            {
    				if(rowData.typeId==1){
    					return "快递员推荐快递员";
    				}else if(rowData.typeId==2){
    					return "加收藏领红包";
    				}else{
    					return "发快递返红包";
    				}
	            },
	            "status": function (column, rowData)
	            {
    				var msg = '';
    				if( rowData.status == 0 )
    				{
    					msg='发送失败';
    				}
    				if( rowData.status == 1 )
    				{
    					msg='发送成功';
    				}	
    				if( rowData.status == 2 )
    				{
    					msg='已删除';
    				}	
    				return msg;
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='</p>';
	   hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
};

var getTheSureTime=function(emp){
	return emp>9?emp:"0"+emp;
}
//时间格式转换
var timeFormatTrans=function(time){
	if(time)
	{
		var newTime= new Date(time);
		var rowText=newTime.getFullYear()+'-'+getTheSureTime((newTime.getMonth()+1))+'-'
		+getTheSureTime(newTime.getDate())+' '+getTheSureTime(newTime.getHours())+':'
		+getTheSureTime(newTime.getMinutes())+':'+getTheSureTime(newTime.getSeconds());
		return rowText;
	}
	else
	{
		return '';
	}	

};



